import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'
import { UserMiddleware } from './common/middleware/user.middleware';
import { GlobalFilter } from './common/filter/global-filter';
import { NestExpressApplication } from '@nestjs/platform-express';

import * as nunjucks from 'nunjucks';
import * as path from 'path';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  app.enableCors()
  const secondOptions = new DocumentBuilder()
    .setTitle('Dogs example')
    .setDescription('The dogs API description')
    .setVersion('1.0')
    .build();
  const dogDocument = SwaggerModule.createDocument(app, secondOptions);
  SwaggerModule.setup('api-doc', app, dogDocument);

  // app.useGlobalFilters(new GlobalFilter())

  const viewPath = path.join(__dirname, './views');
  app.setBaseViewsDir(viewPath);
  app.setViewEngine('njk');
  console.log(viewPath)
  nunjucks.configure(viewPath, {
      noCache: false,
      autoescape: true,
      express: app,
  });
  await app.listen(8084);
}
bootstrap();